package com.ljw;

public class Money implements Expression{
	
	protected int amount;
	protected String currency;

	//생성자
	public Money(int amount, String currency){
		this.amount = amount;
		this.currency = currency;
	}
	
	//equals
	public boolean equals(Object object){
		Money money = (Money)object;
		return amount == money.amount 
				   && currency().equals(money.currency());
	}

	//dollar factory method
	public static Money dollar(int amount) {
		return new Money(amount, "USD");
	}
	
	//franc factory method
	public static Money franc(int amount) {
		return new Money(amount, "CHF");
	}
	
	//getter currency
	public String currency(){
		return this.currency;
	}
	
	public Expression times(int multiplier){
		return new Money(amount*multiplier, currency);
	}
	
	public String toString(){
		return amount + " " + currency;
	}

	//더하기
	public Expression plus(Expression addend) {
		return new Sum(this, addend);
	}
	
	//reduce
	public Money reduce(Bank bank, String to){
		int rate = bank.rate(currency, to);
		return new Money(amount/rate, to);
	}
}